package thread;

/**
 * sleep方法要求我们必须处理终端异常:InterruptedException
 * 当一个线程调用sleep方法处于阻塞状态中,此时该线程的终端方法interrupt()被调用
 * name该线程的阻塞会被立即中断,这时sleep方法会跑出该异常
 *
 * @author Luka
 * @date 2021/06/04 09:08
 **/
public class SleepDemo2 {
    public static void main(String[] args) {
        Thread lin = new Thread(){
            public void run(){
                System.out.println("林:刚美完容睡会儿");
                try {
                    Thread.sleep(50000);
                } catch (InterruptedException e) {
                    try {
                        Thread.sleep(2000);
                    } catch (InterruptedException interruptedException) {
                        interruptedException.printStackTrace();
                    }
                    System.out.println("干嘛呢干嘛呢干嘛呢!");
                }
                System.out.println("林:醒了醒了");

            }
        };
        Thread huang = new Thread(){
            public void run() {
                for (int i = 0; i < 10; i++) {
                    System.out.println("80!");
                    try {
                        Thread.sleep(1000);
                    } catch (InterruptedException e) {
                        e.printStackTrace();
                    }
                }
                System.out.println("咣当!");
                System.out.println("搞定!");
                lin.interrupt();
            }
        };

        lin.start();
        huang.start();
    }

}